//
//  UIApplication+Extension.swift
//  myhub
//
//  Created by x on 2024/6/7.
//

import UIKit

public extension UIApplication {
    static var currentKeyWindow: UIWindow? {
        if #available(iOS 13.0, *), Thread.isMainThread {
            if let window = shared.connectedScenes.filter({ $0.activationState == .foregroundActive }).compactMap({ $0 as? UIWindowScene }).first?.windows.filter({ $0.isKeyWindow }).first {
                return window
            }
            if let window = shared.windows.filter({ $0.isKeyWindow }).last {
                return window
            }
        }

        guard let window = shared.delegate?.window else {
            return shared.keyWindow
        }
        return window
    }
    
    
    static var interfaceOrientation: UIInterfaceOrientation {
        if #available(iOS 13.0, *),
            Thread.isMainThread,
            let orientation = currentKeyWindow?.windowScene?.interfaceOrientation {
                return orientation
        } else {
           return shared.statusBarOrientation
        }
    }
}
